package com.lineage.server.timecontroller.npc;

import com.lineage.server.model.Instance.L1BowInstance;
import com.lineage.server.thread.GeneralThreadPool;
import com.lineage.server.world.WorldBow;
import java.util.HashMap;
import java.util.TimerTask;
import java.util.concurrent.ScheduledFuture;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class NpcBowTimer extends TimerTask {
  private static final Log _log = LogFactory.getLog(NpcBowTimer.class);
  
  private ScheduledFuture<?> _timer;
  
  public void start() {
    int timeMillis = 1500;
    this._timer = GeneralThreadPool.get().scheduleAtFixedRate(this, 1500L, 1500L);
  }
  
  public void run() {
    try {
      HashMap<Integer, L1BowInstance> allBow = WorldBow.get().map();
      if (allBow.isEmpty())
        return; 
      Object[] array;
      int length = (array = allBow.values().toArray()).length;
      int i = 0;
      while (i < length) {
        Object iter = array[i];
        L1BowInstance bowNpc = (L1BowInstance)iter;
        if (bowNpc != null && 
          !bowNpc.isDead()) {
          if (bowNpc.get_start() && bowNpc.checkPc())
            bowNpc.atkTrag(); 
          Thread.sleep(50L);
        } 
        i++;
      } 
    } catch (Exception e) {
      _log.error("固定攻击器时间轴异常重启", e);
      GeneralThreadPool.get().cancel(this._timer, false);
      NpcBowTimer bow = new NpcBowTimer();
      bow.start();
    } 
  }
}
